//
//  AppDelegate.m
//  Blank
//
//  Created by whg－54 on 15/9/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "CultureViewController.h"
#import "BrandDisplayVC.h"
#import "NewsViewController.h"
#import "ForumViewController.h"
//引入首页
#import "HotpotViewController.h"
//引入抽屉
#import "LeftSortViewController.h"
#import <AFNetworking.h>



@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"%d" , [NightModel getColorModel]);
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络");
                break;
            case AFNetworkReachabilityStatusNotReachable:NSLog(@"没有网络");
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
                [alertView show];
                break;
        }
    }];
    
    [manager startMonitoring];
    
#pragma mark - 设置tabbar

    HotpotViewController *hotVC = [[HotpotViewController alloc] init];
    hotVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"shouye" image:[UIImage imageNamed:@"iconfont-zhuye"] tag:100];
    self.mainNavigationController = [[UINavigationController alloc ] initWithRootViewController:hotVC];
    [self.mainNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"background"] forBarMetrics:UIBarMetricsDefault];

    BrandDisplayVC *brandDisplayVC = [[BrandDisplayVC alloc]init];
    UINavigationController *brandNavi = [[UINavigationController alloc]initWithRootViewController:brandDisplayVC];
    brandNavi.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"品牌" image:[UIImage imageNamed:@"iconfont-pinpai"] tag:200];
    [brandNavi.navigationBar setBackgroundImage:[UIImage imageNamed:@"background"] forBarMetrics:UIBarMetricsDefault];
    
    NewsViewController *news = [[NewsViewController alloc] init];
    UINavigationController *newsNavi = [[UINavigationController alloc] initWithRootViewController:news];
    newsNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"更多" image:[UIImage imageNamed:@"iconfont-gengduo"] tag:300];
    [newsNavi.navigationBar setBackgroundImage:[UIImage imageNamed:@"background"] forBarMetrics:UIBarMetricsDefault];
    
    ForumViewController *forum = [[ForumViewController alloc] init];
    UINavigationController *forumNavi = [[UINavigationController alloc] initWithRootViewController:forum];
    forumNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"论坛" image:[UIImage imageNamed:@"iconfont-luntanshequ"] tag:400];
    [forumNavi.navigationBar setBackgroundImage:[UIImage imageNamed:@"background"] forBarMetrics:UIBarMetricsDefault];
    
#pragma mark - tabbar的颜色
    
//    [[UINavigationBar appearance] setBarTintColor:[UIColor purpleColor]];
    
#pragma mark - 创建tb 并把vc放进去
    self.tb = [[UITabBarController alloc] init];
    //tb数组承载一个个v_c
    self.tb.tabBar.tintColor = [UIColor redColor];//item 的颜色默认蓝色
    self.tb.viewControllers = @[self.mainNavigationController , brandNavi, forumNavi, newsNavi];
//    tb.selectedIndex = 2;//默认是第三个

    LeftSortViewController *leftVC = [[LeftSortViewController alloc] init];
    self.LeftSlideVC = [[LeftSlideViewController alloc] initWithLeftView:leftVC andMainView:self.tb];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:self.LeftSlideVC];
    self.window.rootViewController = navi;

    return YES;
}

- (void)afnetPan{
    AFNetworkReachabilityManager * manager = [AFNetworkReachabilityManager sharedManager];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络");
                break;
            case AFNetworkReachabilityStatusNotReachable:NSLog(@"没有网络");
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
                [alertView show];
                break;
        }
    }];
    [manager startMonitoring];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
